﻿using System;
using System.Windows.Forms;
using System.Net.Configuration;

namespace mki.Backup.GUI.Dialogs
{
	/// <summary>
	/// MailSettings form
	/// </summary>
	public partial class MailSettingsForm : Form
	{
		#region Constructors (1)

		/// <summary>
		/// Initializes a new instance of the <see cref="MailSettingsForm"/> class.
		/// </summary>
		public MailSettingsForm()
		{
			InitializeComponent();
		}

		#endregion Constructors

		#region Properties (1)

		/// <summary>
		/// Gets or sets the mail server settings.
		/// </summary>
		/// <value>
		/// The mail server settings.
		/// </value>
		public SmtpSection MailServerSettings
		{
			get
			{
				var smtpSection = new SmtpSection { From = this.fromAddressTextBox.Text };
				smtpSection.Network.Host = this.serverTextBox.Text;
				smtpSection.Network.Port = Int16.Parse(this.portMaskedTextBox.Text);
				smtpSection.Network.UserName = this.userNameTextBox.Text;
				smtpSection.Network.Password = this.passwordTextBox.Text;

				return smtpSection;
			}
			set
			{
				if (value != null)
				{
					this.fromAddressTextBox.Text = value.From;
					if (value.Network != null)
					{
						this.serverTextBox.Text = value.Network.Host;
						this.portMaskedTextBox.Text = value.Network.Port.ToString();
						this.userNameTextBox.Text = value.Network.UserName;
						this.passwordTextBox.Text = value.Network.Password;
					}
				}
			}
		}

		#endregion Properties
	}
}